#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Flask dem."""

from flask import Flask
from flask import request

APP = Flask(__name__)

@APP.route('/act', methods=['get'])
def actions():
    if request.args.get('act'):
        return request.args.get('act')
    if request.args.get('dst'):
        return "71" if request.args.get('dst') == "70" else "70"
    return "invalid args." 

@APP.route('/', methods=['GET', 'POST'])
def home():
    return '<h1>Welcome to the http demo server.</h1>'


@APP.route('/signin', methods=['GET'])
def signin_form():
    return '''<form action="/signin" method="post">
              <p><input name="username"></p>
              <p><input name="password" type="password"></p>
              <p><button type="submit">Sign In</button></p>
              </form>'''


@APP.route('/signin', methods=['POST'])
def signin():
    # 需要从request对象读取表单内容：
    if request.form['username'] == 'admin' and request.form[
            'password'] == 'password':
        return '<h3>Hello, admin!</h3>'
    return '<h3>Bad username or password.</h3>'


if __name__ == '__main__':
    APP.run()